#include <pop.h>
#include <socket.h>
#include <maildir.h>
#include <logging.h>

#define maxUserLen 50
#define maxPassLen 50

/*
* This function is the starting point of the POP protocol
* on the given connection.
*/
void pop_protocol(int connection_descriptor){

	char input[55];
	
	while(scanf("%s", &input){}		// check how to implement
	
	// NOTES: check CRLF pair for commands ... add them in?

	/* AUTHORIZATION phase */
	switch(input){
		case 'USER':
			printf("+OK username accepted\r\n");
		
		case 'PASS':
			printf("+OK authentication complete\r\n");
		
		case 'QUIT':
			/* 
				
			
				NOTE: QUIT command in AUTHORIZATION phase does not move
					  to UPDATE phase, but quits outright
			*/
			printf("+OK\r\n");
		
		default:
			perror("-ERR invalid command\r\n");
			exit(1);
	}

	/* TRANSACTION phase */
	switch(input){
		case 'STAT':
			printf("+OK\r\n");
		
		case 'LIST':
			printf("+OK listing messages\r\n");
		
		case 'RETR':
			printf("+OK\r\n");
		
		case 'DELE':
			printf("+OK message marked for deletion\r\n");
		
		case 'NOOP':
			printf("+OK\r\n");
		
		case 'RSET':
			printf("+OK reset messages marked for deletion\r\n");
		
		case 'QUIT':
			printf("+OK moving to UPDATE phase\r\n");
		
			/* UPDATE phase */
			
			break;
		
		default:
			perror("-ERR invalid command\r\n");
			exit(1);
	}

}

